package haxeframe.physics.fixtures;

import box2D.collision.shapes.B2PolygonShape;
import box2D.common.math.B2Vec2;
import box2D.dynamics.B2FixtureDef;

import flash.geom.Point;

import haxeframe.physics.Assets;
import haxeframe.utils.MathUtils;

class FixturePolygon extends Fixture
{
	public function new(xml:Xml, scale:Float, symbolScale:Float){
		super(xml, scale, symbolScale);
	}

	public function FixturePolygon()
	{
	}
	
	public override function init():Void
	{
		super.init();
		// if(_xml.exists("material")) material = Assets.getMaterial(_xml.get('material'));
		
		// var vertices:Array<Point> = new Array<Point>();
		// var coords:Array<String> = _xml.get('vertices').split(",");
		// var n:Int = coords.length;
		
		// for (v in 0...n)
		// {
		// 	if((v+2 % 2) == 0)
		// 		vertices.push(new Point(Std.parseFloat(coords[v]) , Std.parseFloat(coords[v + 1])));
		// }
		
		// var points:Array<Point> = [];
		// n = vertices.length;
		
		// for (v in 0...n)
		// {
		// 	var p:Point = vertices[v];
		// 	if (p != null)
		// 	{
		// 		var px:Float = (p.x + Std.parseFloat(_xml.get('x')))*_symbolScale;
		// 		var py:Float = (p.y + Std.parseFloat(_xml.get('y')))*_symbolScale;
		// 		points.push(new Point(px, py));
		// 	}
		// }
		
		// var triangles:Array<Dynamic> = MathUtils.triangulate(points);
		
		// if (triangles != null)
		// {
			
		// 	n = Std.int(triangles.length / 3);
		// 	for (v in 0...n)
		// 	{
		// 		var index:Int = v * 3;
		// 		var p0:Point = triangles[index];
		// 		var p1:Point = triangles[index+1];
		// 		var p2:Point = triangles[index+2];
				
		// 		var v0:B2Vec2 = new B2Vec2(p0.x / _scale, p0.y / _scale);
		// 		var v1:B2Vec2 = new B2Vec2(p1.x / _scale, p1.y / _scale);
		// 		var v2:B2Vec2 = new B2Vec2(p2.x / _scale, p2.y / _scale);
				
		// 		var polyShape:B2PolygonShape = new B2PolygonShape();
		// 		polyShape.setAsArray([v0, v1, v2], 3);

				
		// 		var def:B2FixtureDef = new B2FixtureDef();
		// 		def.shape = polyShape;
				
		// 		if (material != null){
		// 			def.density = material.density;
		// 			def.friction = material.friction;
		// 			def.restitution = material.restitution;
		// 		} else {
		// 			if (_xml.exists("density")) def.density = Std.parseFloat(_xml.get('density'));
		// 			if (_xml.exists("friction")) def.friction = Std.parseFloat(_xml.get('friction'));
		// 			if (_xml.exists("restitution")) def.restitution = Std.parseFloat(_xml.get('restitution'));
		// 		}
				
		// 		if (_xml.get("isSensor") == 'true') def.isSensor = true;
				
		// 		definitions.push(def);
		// 	}
		// }
	}
}